package com.tiancai.service.mpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tiancai.pojo.po.UserRole;
import com.tiancai.mapper.UserRoleMapper;
import com.tiancai.service.IUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tiancai
 * @since 2025-04-03
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Override
    public List<String> getRolesByUserId(Long id) {
        //根据用户id返回用户的所有角色数组
        //查找到所有符合的UserRole对象，用List<String>返回所有的角色
        List<String> roles = new ArrayList<String>();
        for (UserRole userRole : list(new QueryWrapper<UserRole>().lambda().eq(UserRole::getUserId, id))) {
            roles.add(userRole.getRole());
        }
        return roles;
    }
}
